import type { RouteLocation, Router } from 'vue-router';
// 地址拦保存搜索条件
const pathReplace = (
  $router: Router,
  $route: RouteLocation | null,
  params: Record<string, any>,
): void => {
  const temp: { [key: string]: any } = {};
  const p = $route ? { ...$route.query, ...params } : params;
  Object.keys(p).forEach((item) => {
    if (!['[]', '{}'].includes(JSON.stringify(p[item]))) {
      if (p[item] && !/.*,.*/.test(p[item])) {
        if (!['ps'].includes(item)) {
          temp[item] = p[item];
        }
      }
    }
  });
  $router.replace({ query: temp });
};
export default pathReplace;
